package com.ldcc.report_system.util;

import android.app.Activity;
import android.view.View;
import android.widget.TextView;

import androidx.appcompat.app.AlertDialog;
import com.ldcc.report_system.R;
/***
 * @author wwj[yeshengkele@outlook.com]
 * @description 加载动画
 */
public class LoadingUtil {

    /**
     * 打开以对话框为基础的加载动画
     *
     * @param title    标题
     * @param msg      信息
     * @param activity 需要显示的上下文
     * @return 返回对话框
     */
    public static AlertDialog dialogLoadingOpen(String title, String msg, Activity activity) {
        AlertDialog.Builder builder = new AlertDialog.Builder(activity);
        View loadingLayout = activity.getLayoutInflater().inflate(R.layout.loading, null);
        TextView loadingText = loadingLayout.findViewById(R.id.loading_text);
        loadingText.setText(msg);
        AlertDialog alertDialog = builder.setTitle(title)
                .setView(loadingLayout)
                .create();
        // 取消对话框的关闭
        alertDialog.setCanceledOnTouchOutside(false);
        alertDialog.show();
        return alertDialog;
    }


    /**
     * 关闭对话框
     *
     * @param alertDialog 需要关闭的对话框对象
     */
    public static void dialogLoadingClose(AlertDialog alertDialog) {
        // 关闭
        alertDialog.dismiss();
    }


}
